export default {
  data() {
    return {
      insuList: [],
      id: 0,
      carid: '',
      basicInformation: {},
      currentIndex: 0
    }
  },
  created() {
    this.insurance()
  },
  onLoad(types) {
    this.currentIndex = Number(types.currentIndex)
    this.carid = types.carid
    this.GetCarData()
  },
  methods: {
    //保险公司
    async insurance() {
      try {
        const res = await this.$api.jsonData.insurance()
        this.insuList = res.data
      } catch (err) {
        console.log(err)
      }
    },
    //获取我的爱车--基本信息
    async GetCarData() {
      try {
        let data = {
          carid: this.carid
        }
        const res = await this.$api.commodity.GetCarData(data)
        this.basicInformation = res.data
      } catch (e) {
        console.log(e)
      }
    },
    //选择保险公司
    insClick(id) {
      this.id = id
      this.UpdateCarInsuranceData()
    },
    //获取我的爱车--修改爱车保险数据
    async UpdateCarInsuranceData() {
      try {
        let data = {
          account_car_id: this.carid, //爱车id
          insurance_id: this.id, //保险公司id
          duetotime: this.basicInformation.insurance.duetotime, //保险到期时间
          car_master: this.basicInformation.insurance.car_master, //主车名称
          cardnumber: this.basicInformation.insurance.cardnumber, //身份证号码
          cityid: this.basicInformation.insurance.cityid, //投保城市id
          city: this.basicInformation.insurance.city, //投保城市名称
          transfer: this.basicInformation.insurance.transfer //一年内是否过户
        }
        const res = await this.$api.commodity.UpdateCarInsuranceData(data)
        if (res.data) {
          uni.redirectTo({
            url: '/pages_commodity/mylovecarInformation/mylovecarInformation?index=' + this.currentIndex + '&current=0' +
              '&state=3'
          })
        }

      } catch (e) {
        console.log(e)
      }
    },

  }
}
